package com.es.stack;

import java.util.LinkedList;
import java.util.List;

/**
 * @author 二十
 */
public class LinkedListStack<E> extends AbstractStack<E> {

    private List<E> queue = new LinkedList<>();

    @Override
    public void push(E e) {
        queue.add(e);
    }

    @Override
    public E pop() {
        return queue.remove(queue.size() - 1);
    }

    @Override
    public E peek() {
        return queue.get(queue.size() - 1);
    }

    @Override
    public int getSize() {
        return queue.size();
    }

    @Override
    public boolean isEmpty() {
        return queue.isEmpty();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Stack:[");
        for (int i = queue.size() - 1; i >= 0; i--) {
            sb.append(queue.get(i));
            if (i != 0) {
                sb.append("->");
            }
        }
        return sb.append("]").toString();
    }
}
